package com.dubbo.cp.consumer.service;

import org.apache.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Service;

import com.dubbo.cp.service.LogService;
import com.dubbo.cp.service.PayService;

import io.seata.core.context.RootContext;
import io.seata.spring.annotation.GlobalTransactional;

@Service
public class SeataService {

	@Reference
	private PayService payService;

	@Reference
	private LogService logService;

	@GlobalTransactional
	public boolean pay() {
		System.out.println("开始全局事务，XID = " + RootContext.getXID());
		
		payService.doPay();

		logService.sendUserLog("Admin", "访问 DEMO seata");
		logService.sendDemoLog("访问-DEMO seata");
		throw new RuntimeException("Test Rollback");
//		return true;
	}
}
